// pages/tijiao/tijiao.js
const app = getApp()
const util = require('../../utils/util.js');

Page({

  data: {

    xingming:0,
    xuehao:0,
    chengji:0,
  },
  formSubmit: function (e) {
    
    //console.log(e.detail.value);
    if (e.detail.value.xingming.length == 0 || e.detail.value.xingming.length >= 20) {

      wx.showToast({

        title: '姓名不能为空或过长!',

        icon: 'loading',

        duration: 1500

      })

      setTimeout(function () {

        wx.hideToast()

      }, 2000)

     } 
    
     
     else if (e.detail.value.xuehao.length == 0) {

      wx.showToast({

        title: '学号不能为空!',

        icon: 'loading',

        duration: 1500

      })

      setTimeout(function () {

        wx.hideToast()

      }, 2000)

    } 
    // else if (e.detail.value.chengji.length == 0) {

    //   wx.showToast({

    //     title: '成绩不能为空!',

    //     icon: 'loading',

    //     duration: 1500

    //   })

    //   setTimeout(function () {

    //     wx.hideToast()

    //   }, 2000)

    // } 


    else {


      wx.request({

        // url: util.basePath + '/from.php',
         url:'https://qimo.leceshi.cn/from.php',
        header: {

          "Content-Type": "application/x-www-form-urlencoded"

        },

        method: "POST",

        data: { xingming: e.detail.value.xingming,  xuehao:e.detail.value.xuehao, chengji:e.detail.value.chengji},

        success: function (res) {
          console.log(res.data);
          if (res.data.status == 0) {

            wx.showToast({

              title: '提交失败！！！',

              icon: 'loading',

              duration: 1500

            })

          } else {

            wx.showToast({

              title: '提交成功！！！',//这里打印出登录成功

              icon: 'success',

              duration: 1000

            })

          }

        }

      })

    }

  },

})